﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DrinkTest.Question;

namespace DrinkTest.Answer
{
    class Libby : IDrinkTest
    {
        public long GetSumSat(int[] S, int[] A)
        {
            if(S.Length==0||A.Length==0||S.Length!=A.Length)
            {
                return -1;
            }

            List<SatisEntry> SatisList = new List<SatisEntry>();

            for (int i = 0; i < S.Length;i++ )
            {
                SatisList.Add(new SatisEntry(S[i],A[i]));
            }

            List<SatisEntry> SortedSatList = SatisList.OrderByDescending(se=>se.si).ToList();

            if (SortedSatList[SortedSatList.Count-1].si == 0)
            {
                return 0;
            }

            int sumSat = 0;
            int sumA=0;

            foreach(SatisEntry SE in SortedSatList)
            {
                if (SE.ai >= 100 - sumA)
                {
                    sumSat += (100 - sumA) * SE.si;
                    return sumSat;
                }
                else
                {
                    sumSat += SE.ai * SE.si;
                    sumA += SE.ai;
                }
            }

            return -1;

        }

       

        public class SatisEntry
        {
            
            public int si { get; set; }
            public int ai { get; set; }

            public SatisEntry(int si,int ai)
            {
                this.si = si;
                this.ai = ai;
            }
        }
    }
}
